#include "Camera.h"

Camera::Camera(void) 
{
	//set matrices to identity
	viewMatrix = XMMatrixIdentity();
	projectionMatrix = XMMatrixIdentity();
	yaw = 0;
	pitch = 0;
	roll = 0;
	position = XMVectorSet(0,0,0,0);
}

Camera::~Camera(void)
{
}

void Camera::UpdateCamera(int elapsedTime)
{		
	  //up=XMVectorSet(0.0f,1.0f,0.0f,1);
	  //look=XMVectorSet(0.0f,0.0f,1.0f,1);
	  //right=XMVectorSet(1.0f,0.0f,0.0f,1);

	  //XMMATRIX yawMatrix;
	  //yawMatrix = XMMatrixRotationAxis(up, yaw);
	  //look = XMVector3TransformCoord(look, yawMatrix); 
	  //right = XMVector3TransformCoord(right, yawMatrix);

	  //XMMATRIX pitchMatrix;
	  //pitchMatrix = XMMatrixRotationAxis(right, pitch);
	  //look = XMVector3TransformCoord(look, pitchMatrix); 
	  //up = XMVector3TransformCoord(up, pitchMatrix);

	  //XMMATRIX  rollMatrix;
	  //rollMatrix = XMMatrixRotationAxis(look, roll);
	  //right = XMVector3TransformCoord(right, rollMatrix); 
	  //up = XMVector3TransformCoord(up, rollMatrix);
	  //
	  //viewMatrix = XMMatrixIdentity();	  
	  //viewMatrix._11 = XMVectorGetX(right);
	  //viewMatrix._12 = XMVectorGetX(up); 
	  //viewMatrix._13 = XMVectorGetX(look);
	  //viewMatrix._21 = XMVectorGetY(right);
	  //viewMatrix._22 = XMVectorGetY(up); 
	  //viewMatrix._23 = XMVectorGetY(look);
	  //viewMatrix._31 = XMVectorGetZ(right);
	  //viewMatrix._32 = XMVectorGetZ(up); 
	  //viewMatrix._33 = XMVectorGetZ(look);
	  //viewMatrix._41 = - XMVectorGetX(XMVector3Dot( position, right ));  ///LUSITANO, pq nao devolve um FLOAT ??? (... SSE optimizations ... KKk)
	  //viewMatrix._42 = - XMVectorGetX(XMVector3Dot( position, up ));
	 //viewMatrix._43 = - XMVectorGetX(XMVector3Dot( position, look ));


      XMMATRIX cameraRotation = XMMatrixRotationAxis(XMVectorSet(0,1,0,0),yaw) * XMMatrixRotationAxis(XMVectorSet(1,0,0,0),pitch);

	  XMVECTOR cameraOriginalTarget = XMVectorSet(0, 0, -1,0);
	  XMVECTOR cameraOriginalUpVector = XMVectorSet(0, 1, 0,0);

	  XMVECTOR cameraRotatedTarget = XMVector3TransformCoord(cameraOriginalTarget, cameraRotation);
      _target = position + cameraRotatedTarget;

      XMVECTOR _up = XMVector3TransformCoord(cameraOriginalUpVector, cameraRotation);

	  viewMatrix = XMMatrixLookAtLH(position, _target,_up);

}

void Camera::SetPerspectiveProjection(float fov,float aspectRatio, float zNear, float zFar)
{	
	projectionMatrix = XMMatrixPerspectiveFovLH( fov, aspectRatio, zNear, zFar );	
}
void Camera::AddYawPitchRoll(float Yaw,float Pitch,float Roll)
{
    yaw += Yaw ;
	pitch += Pitch;              
	roll += Roll ;  
}

void Camera::SetYawPitchRoll(float Yaw,float Pitch,float Roll)
{
    yaw = Yaw ;
	pitch = Pitch;              
	roll = Roll ;  
}